package org.helgoboss.single_source_builder_main

import java.io.File

class ScalaLanguage extends Language {

    def analyzeSourceCode(sourceCode: String) = {
        null
    }
    
    def generateTargetSourceFileLocation(projectDescriptor: ProjectDescriptor) = {
        import projectDescriptor.artifact._
        val pathToDirFromRootPackage = (groupId + "/" + artifactId).replaceAll("-", "_").replaceAll("""\.""", "/")
        val fileName = projectDescriptor.primaryClassName + ".scala"
        new File("src/main/scala/" + pathToDirFromRootPackage + "/" + fileName)
    }
    
    def generatePluginsXml(projectDescriptor: ProjectDescriptor) = {
        val scalaVersion = projectDescriptor.dependencies.find(_.artifactId == "scala-library").getOrElse(error("Need Scala library dependency")).version
        
        <plugin>
            <groupId>org.scala-tools</groupId>
            <artifactId>maven-scala-plugin</artifactId>
            <version>2.13.1</version>
            <configuration>
                <scalaVersion>{scalaVersion}</scalaVersion>
            </configuration>
            <executions>
                <execution>
                    <id>scala-compile</id>
                    <phase>process-resources</phase>
                    <goals>
                        <goal>compile</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    }
}